'''
Created on Jan 18, 2010

@author: christianp
'''
import wx
import urllib2
import cStringIO
import time

class ImageRequest(object):

    def __init__(self):
        '''ImageRequest'''
    
    def getImageFromServer(self, uri, do_after):
        img = None
        duration = time.time()
        try:
            url = uri
            image_stream = urllib2.urlopen(url).read()
            
            stream = cStringIO.StringIO(image_stream)
            
            img = wx.ImageFromStream(stream)
            
        except:
            print("Conncection was aborted by host machine")
            print("Failed: " + uri)

        do_after(img, (time.time() - duration))